﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.ServiceModel;
using System.Text;
using System.Windows.Forms;
using Aker.DevTeam;
using DevExpress.Utils;
using DevExpress.XtraNavBar;
using Extensions;

namespace Aker
{
    public partial class Reports : XForm
    {
        public Reports()
        {
            InitializeComponent();
        }

        DataSet ds;
        private void Reports_Load(object sender, EventArgs e)
        {
            cmbFair.Items.Add(Language.Reports.AllFairs);

            DataTable dt = Data.DM.ExecuteDataTable("GetFairs");
            foreach (DataRow dr in dt.Rows)
                cmbFair.Items.Add(dr["Fair"].ToString());

           

            DevExpress.XtraNavBar.NavBarGroup grp = new DevExpress.XtraNavBar.NavBarGroup();
            grp.Caption = Language.Reports.FairReports; 
            navBar.Groups.Add(grp);

            grp.ItemLinks.Add(AddReportItem(Language.Reports.DetayliListe));
            grp.ItemLinks.Add(AddReportItem(Language.Reports.IletisimBilgileri));
            grp.ItemLinks.Add(AddReportItem(Language.Reports.ArtikelBazli));
            grp.ItemLinks.Add(AddReportItem(Language.Reports.AdresBazli));
            grp.ItemLinks.Add(AddReportItem(Language.Reports.GunlukYogunluk));
            grp.ItemLinks.Add(AddReportItem(Language.Reports.SaatlikYogunluk));
            grp.ItemLinks.Add(AddReportItem(Language.Reports.GünSaatlikYogunluk));
            grp.ItemLinks.Add(AddReportItem(Language.Reports.TestOlarakKabulEdilenler));
            grp.ItemLinks.Add(AddReportItem(Language.Reports.KartelaGonderileceklerRaporu));

            grp.Expanded = true;
 
           
            cmbFair.SelectedIndex = 0;
        }

        string Fair
        {
            get
            {
                string fair = "";
                if (cmbFair.SelectedIndex > 0)
                    fair = cmbFair.SelectedItem.ToString();
                return fair;
            }
        }

        int itemIndex = 0;
        private NavBarItem AddReportItem(string Caption)
        {
            DevExpress.XtraNavBar.NavBarItem item;
            item = new DevExpress.XtraNavBar.NavBarItem();
            item.Caption = Caption;
            item.LinkPressed += item_LinkPressed;
            item.Tag = itemIndex++;
            return item;
        }

        int lastIndex = 0;
        void item_LinkPressed(object sender, NavBarLinkEventArgs e)
        {
            int index = (int)e.Link.Item.Tag;
            lastIndex = index;
            BindData();
        }

        bool RefreshNeeded = true;

        private void BindData()
        {
            this.Cursor = Cursors.WaitCursor;
            if (RefreshNeeded)
                ds = Data.DM.ExecuteDataSet("GetReport", Fair);
            gv1.Init(ds.Tables[lastIndex]);
            gv1.OptionsView.ShowViewCaption = false;
            gv1.MakeReadOnly();
            gv1.BestFitColumns();
            gv1.Columns["Fair"].Visible = cmbFair.SelectedIndex == 0;
             
            gv1.OptionsView.ShowViewCaption = true;
            gv1.ViewCaption = navBar.Groups[0].ItemLinks[lastIndex].Caption;
            gv1.Focus();

            RefreshNeeded = false;
            this.Cursor = Cursors.Default;
        }
 
        private void cmbFair_SelectedIndexChanged(object sender, EventArgs e)
        {
            RefreshNeeded = true;
             BindData();
        }
    }
}
